package goroutine

import (
	"runtime"
	"time"
	"fmt"
)

func Goroutine_sample () {
	// 创建范围数据
	//data := slice.CreateIntSlice(0, 50000000)
	numRoutine := runtime.NumCPU()
	t1 := time.Now()
	result := SumByRoutine(0, 50000000)
	t2 := time.Now()
	fmt.Println(fmt.Sprintf("5000万 %d goroutine耗时 ", numRoutine), t2.Sub(t1), result)

	t1 = time.Now()
	result = Sum(0, 50000000)
	t2 = time.Now()
	fmt.Println("5000万 for 耗时 ",t2.Sub(t1), result)

	// 创建范围数据
	//data = slice.CreateIntSlice(0, 500000000)

	t1 = time.Now()
	result = SumByRoutine(0, 500000000)
	t2 = time.Now()
	fmt.Println(fmt.Sprintf("5亿 %d goroutine耗时 ", numRoutine), t2.Sub(t1), result)

	t1 = time.Now()
	result = Sum(0, 500000000)
	t2 = time.Now()
	fmt.Println("5亿 for  耗时 ",t2.Sub(t1), result)

}